//
//  MeatShopCartBox.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/22.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatShopCartBox.h"
#import "MeatShopCartHeader.h"
#import "MeatShopCartTableViewCell.h"

//展示Viwe高度
#define kCategoryHeight 364

@interface MeatShopCartBox()<UITableViewDelegate, UITableViewDataSource>


/**
 MeatShopCartBox 's TableView -> UITableView
 */
@property (nonatomic, strong) UITableView *tableView;


/**
 MeatShopCartBox 's Header -> UIView
 */
@property (nonatomic, strong) MeatShopCartHeader *header;


@end


@implementation MeatShopCartBox


- (void)setupUI{
    
    [super setupUI];
    
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    self.contentView.backgroundColor = KClearColor;
    [self.contentView addSubview:self.tableView];

}

- (void)setupContentLayout{
    
    self.height = KScreenHeight - (TJ_SafeAreaBottomHeight + TJ_MeatShop_Bottomer);
    
    {
        self.contentView.mj_x = 0;
        self.contentView.mj_y = KScreenHeight - (TJ_SafeAreaBottomHeight + TJ_MeatShop_Bottomer) - kCategoryHeight;
        self.contentView.width = KScreenWidth;
        self.contentView.height = kCategoryHeight;
    }
    
    {
        self.tableView.frame = CGRectMake(0, 0, KScreenWidth, kCategoryHeight);
    }
}


#pragma mark - tableview delegate/dataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 52;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    return self.header;
}


- (void)scrollTableViewTop{
    kWeakSelf(self);
    NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:1];
    [weakself.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 86;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MeatShopCartTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeatShopCartTableViewCell"];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark - getter and setter

#pragma mark - setter and getter

- (UITableView *)tableView
{
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = KClearColor;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.rowHeight = 86;
        [_tableView registerClass:[MeatShopCartTableViewCell class] forCellReuseIdentifier:@"MeatShopCartTableViewCell"];
    }
    return _tableView;
}


- (MeatShopCartHeader *)header{
    if (!_header) {
        _header = [[MeatShopCartHeader alloc] init];
    }
    return _header;
}


@end
